import numpy as np
from scipy.optimize import linear_sum_assignment

def read_input(file_path):
    with open(file_path, 'r') as file:
        data = file.readlines()
    n = int(data[0])
    M = np.array([[int(x) for x in data[i+1].split()] for i in range(n)])
    F = np.array([[int(x) for x in data[n+1+i].split()] for i in range(n)])
    return n, M, F

def max_advantage_pairing(M, F):
    row_ind, col_ind = linear_sum_assignment(-(M + F.T))
    max_advantage = -(M[row_ind, col_ind] + F[col_ind, row_ind]).sum()
    return max_advantage

if __name__ == "__main__":
    n, M, F = read_input('input.txt')
    max_advantage = max_advantage_pairing(M, F)
    with open('output.txt', 'w') as file:
        file.write(str(max_advantage))
